

interface TipsStruct {
	name?: string;
	desc: string;
}

/**
 * 通用的标题文本tips，data{name:'string',desc:'string'}，任意一项可为空，不显示
 */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
class CommonTips extends eui.Component {
	lbName: eui.Label;

	lbDesc: TextWithImage;

	data: TipsStruct;

	constructor(data: TipsStruct) {
		super();
		this.data = data;
		this.skinName = 'tips_common';
		//		allCenter(this);
	}

	protected override childrenCreated(): void {
		super.childrenCreated();
	}

	private static instance: CommonTips;

	public static ins(): CommonTips {
		if (!this.instance) {
			this.instance = new CommonTips(null);
		}
		return this.instance;
	}

	setData(data: TipsStruct): void {
		this.data = data;
		if (this.lbDesc) {
			this.lbDesc.label.size = 23;
			this.lbDesc.label.textColor = 0xd9d9d9;
			this.lbDesc.label.lineSpacing = 2.5;
			this.lbDesc.text = this.data.desc;
			this.width = Math.max(this.lbDesc.textField.textWidth, this.lbName.textWidth) + 20;
			// ui.msglog('this.width', this.width);
		}
	}

	setPos(touchPosX: number, touchPosY: number, sWidth: number, sHeight: number): void {
		// const sWidth = getStageWidth();
		// const sHeight = getStageHeight();
		const ajustX = 10;

		this.x = touchPosX > sWidth / 2 ? touchPosX - this.width - ajustX : touchPosX + ajustX;
		this.y = touchPosY + this.height > sHeight ? touchPosY - this.height : touchPosY;
		// ui.msglog({x: this.x, y: this.y, touchPosX, touchPosY,});
	}
}
